/*
 *	Copyright (c) 2013, Yulong Information Technologies
 *	All rights reserved.
 *  
 *  @Project: Db
 *  @author: Robot
 *	@email: feng88724@126.com
 */
package com.example.db.core;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * @author Robot
 * @weibo http://weibo.com/feng88724
 * @date Apr 10, 2013	
 */
public class DatabaseHelper extends SQLiteOpenHelper {
	
	/**
	 * @param context
	 * @param name
	 * @param factory
	 * @param version
	 */
	public DatabaseHelper(Context context, String name, CursorFactory factory, int version) {
		super(context, name, factory, version);
	}

	//第一次创建数据库时调用
	@Override
	public void onCreate(SQLiteDatabase db) {
		for(Class<?> model: DBConfig.models) {
			String sql = ModelBuilder.createTableSQL(model);
			db.execSQL(sql);
		}
	}
	
	//更新时调用
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//		//删除后再增加
//		if(DBConfig.DATABASE_UPDATE_STRATEGY){
//			for(Class<?> model: DBConfig.models) {
//				//删除表结构
//				db.execSQL(DatabaseBuilder.dropTableSQL(model));
//				//再增加表结构
//				db.execSQL(DatabaseBuilder.createTableSQL(model));
//			}
//		}else{
//			//只更新增加的表或列
//			DatabaseBuilder.updateTables(db);
//		}
	}

}
